// pages/users/intention/index.js
const {
  fillingAdd,
  fillingEdit,
  fillingInfo
} = require('../../../api/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    advantageIndustry: "",
    colorBlindness: "",
    colorWeakness: "",
    createBy: "",
    createTime: "",
    familySituation: "",
    futureDirection: "",
    height: "",
    hobby: "",
    id: null,
    intentionProvinces: "",
    intentionUniversityLevel: "",
    isDisability: false,
    isSurgery: false,
    medicalHistory: "",
    pluses: "",
    specialty: "",
    target: "",
    updateBy: "",
    username: "",
    vision: "",
    weight: ""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.loadData()
  },
  async loadData() {
    const {
      result
    } = await fillingInfo()
    if (result) {
      const {
        advantageIndustry,
        colorBlindness,
        colorWeakness,
        createBy,
        createTime,
        familySituation,
        futureDirection,
        height,
        hobby,
        id,
        intentionProvinces,
        intentionUniversityLevel,
        isDisability,
        isSurgery,
        medicalHistory,
        pluses,
        specialty,
        target,
        updateBy,
        updateTime,
        username,
        vision,
        weight
      } = result
      this.setData({
        advantageIndustry,
        colorBlindness,
        colorWeakness,
        createBy,
        createTime,
        familySituation,
        futureDirection,
        height,
        hobby,
        id,
        intentionProvinces,
        intentionUniversityLevel,
        isDisability: isDisability === 1 ? true : false,
        isSurgery: isSurgery === 1 ? true : false,
        medicalHistory,
        pluses,
        specialty,
        target,
        updateBy,
        updateTime,
        username,
        vision,
        weight
      })
      // console.log(this.data.isDisability,this.data.isSurgery)
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  inputChange(e) {
    const {
      type
    } = e.currentTarget.dataset
    this.setData({
      [type]: e.detail.value
    })
  },
  switchChange(e) {
    const {
      type
    } = e.currentTarget.dataset
    this.setData({
      [type]: e.detail.value
    })
  },
  async submit(e){
    const params=e.detail.value
    const {isDisability,isSurgery,id}=this.data
    params.isDisability=isDisability?1:0
    params.isSurgery=isSurgery?1:0
    params.id=id
    if(id){
      const {result}=await fillingEdit(params)
    }else{
      const {result}=await fillingAdd(params)
    }
    
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

})